const { getMemberList, getHzList } = require("../request");
const cookie =
  "_csrf=1TOcXlSy3u5PLZqFC2lU7fSO; UM_distinctid=17bcde6309c4cc-06490fc581174f-a7d193d-1fa400-17bcde6309ddfe; CNZZDATA1275376637=314104608-1631240274-%7C1631240274; SESSDATA=76218e68%2C1646799044%2Cb4f0c%2A91; bili_jct=067482ae3a338d8499f7fb2154e9d145; DedeUserID=187635557; DedeUserID__ckMd5=c405e2609fcaa605; sid=6ucebf4x; session-api=9er8h7lmar1b82ffddud1u2ehu; user-info=17538986";
module.exports = async (ctx, next) => {
  const memberList = await getMemberList(cookie);
  const hzList = await getHzList(cookie);
  hzList.forEach((item) => {
    item["damage_list"].forEach((list) => {
      item[list["boss_name"]] = list["damage"];
    });
  });
  const keyMap = [
    "damage_num",
    "damage_total",
    "user_id",
    "user_name",
    "damage_list",
  ];
  memberList.forEach((member) => {
    keyMap.forEach((key) => {
      member[key] = 0;
    });
    hzList.forEach((hz) => {
      if (member.id == hz.user_id) {
        keyMap.forEach((key) => {
          member[key] = hz[key];
        });
      }
    });
  });
  memberList.sort((a, b) => {
    return b.damage_total - a.damage_total;
  });
  await ctx.render("./selectHz.ejs", {
    memberList: memberList,
  });
};
